package service

import (
	"mlss-cc-a/models"
	"mlss-cc-a/repo/v2"
	"mlss-cc-a/restapi/operations/person"
)

func GetPersonList(params person.GetPersonListParams) (*models.PersonList, error) {
	list, err := repo.PersonRepo.GetPersonList(params.ID)
	if err != nil {
		return nil, err
	}

	peopleList := make([]*models.Person, len(list))
	for i, v := range list {
		peopleList[i] = &models.Person{
			Birth: v.Birth,
			Code:  v.Code,
			Email: v.Email,
			ID:    v.ID,
			Name:  v.Name,
			Phone: v.Phone,
		}
	}
	var rst = models.PersonList{
		List: peopleList,
	}
	return &rst, nil
}
